/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


package gui;

import delegate.GestionDelegate;
import controlacciones.ejb3.entity.TbAccion;
import controlacciones.ejb3.pojo.TableBeanBinding_DatosAccionesAprobar;
import controlaccionescomercial.ControlAccionesComercialView;
import helper.JP_Utiles_PanelModelo;
import helper.JP_Utiles_PanelBotonesMantenimiento;
import helper.Utiles_MensajesDialogo;
import helper.Utiles_Panel;
import java.awt.BorderLayout;

import java.beans.PropertyVetoException;
import org.jdesktop.application.Task;
import java.util.ArrayList;
import java.util.List;
import org.jdesktop.application.Action;
import org.jdesktop.beansbinding.BindingGroup;

/**
 *
 * @author Vanessa
 */
public class JP_AprobarAcciones extends JP_Utiles_PanelModelo {
    

    /** Creates new form JP_RegistraAccion */
    public JP_AprobarAcciones() {
        inicializaComponentes();
    }

    private void inicializaComponentes(){
        initComponents();
        //Panel de Operaciones
        ArrayList alBotones = new ArrayList( 1 );        
        alBotones.add( new Integer( JP_Utiles_PanelBotonesMantenimiento.BOTON_GUARDAR ) );
        alBotones.add( new Integer( JP_Utiles_PanelBotonesMantenimiento.BOTON_DESHACER ) );
        alBotones.add( new Integer( JP_Utiles_PanelBotonesMantenimiento.BOTON_CERRAR ) );

        jp_ope = new JP_Utiles_PanelBotonesMantenimiento( this, alBotones );
        jp_Operaciones.setLayout( new BorderLayout() );
        jp_Operaciones.add( jp_ope, BorderLayout.CENTER );          

        btnBuscar.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        btnBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/fife/plaf/Office2003/find.gif"))); // NOI18N
        btnBuscar.setText("Buscar");

        tbAccion = null;
        refrescar();        
        inicializarBotones();
    }   

    public void inicializaReferencias(){
    }

    private void cargaTabla( String inicio, String fin){
        
        if( inicio.trim().equals("/  /") ||  inicio.trim().equals("") || fin.trim().equals("/  /") || fin.trim().equals("") ){
            inicio = "";
            fin = "";
        }

//        System.err.println( "Fecha de inicio:" + inicio);
//        System.err.println( "Fecha de fin:" + fin);
        try {
            listaDatos = GestionDelegate.getInstance().getListaAccionesAprobar( inicio, fin);
            numeroAccionesField.setText( listaDatos.size() + "" );
        } catch (Exception ex) {
            //Logger.getLogger( JP_AprobarAcciones.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println( "Error al cargar la lista de Acciones por Aprobar" );
        }
        try{
            
            bindingGroup = new org.jdesktop.beansbinding.BindingGroup();
            jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, listaDatos, tabla);
            org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idAccion}"));
            columnBinding.setColumnName("Cod Accion");
            columnBinding.setColumnClass(Integer.class);
            columnBinding.setEditable( false );
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${fechaRegistro}"));
            columnBinding.setColumnName("F. Registro");
            columnBinding.setColumnClass(String.class);
            columnBinding.setEditable( false );
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${fechaEnvio}"));
            columnBinding.setColumnName("F. Envio");
            columnBinding.setColumnClass(String.class);
            columnBinding.setEditable( false );
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${fechaAtencion}"));
            columnBinding.setColumnName("F. Atención");
            columnBinding.setColumnClass(String.class);
            columnBinding.setEditable( false );
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${codClasificacionAccion}"));
            columnBinding.setColumnName("Clasificación");
            columnBinding.setColumnClass(String.class);
            columnBinding.setEditable( false );
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${codTipoAccion}"));
            columnBinding.setColumnName("Cod Tipo Acción");
            columnBinding.setColumnClass(String.class);
            columnBinding.setEditable( false );
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${codArea}"));
            columnBinding.setColumnName("Area");
            columnBinding.setColumnClass(String.class);
            columnBinding.setEditable( false );
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${aprobada}"));
            columnBinding.setColumnName("Aprobada");
            columnBinding.setColumnClass(Boolean.class);
            columnBinding.setEditable( true );
            bindingGroup.addBinding(jTableBinding);

            bindingGroup.bind();
            if(listaDatos != null){
                if(listaDatos.size() > 0 )
                    this.tabla.setRowSelectionInterval(0, 0);
            }
            }catch( Exception e ){
                //Logger.getLogger( JP_AprobarAcciones.class.getName()).log(Level.SEVERE, null, e);
                System.out.println( "Error en el binding" );
            }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always re-generated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        comboBeanBindingArea1 = new beansbinding.ComboBeanBindingArea();
        comboBeanBindingTbClasificacionAccion1 = new beansbinding.ComboBeanBindingTbClasificacionAccion();
        comboBeanBindingTbTipoAccion1 = new beansbinding.ComboBeanBindingTbTipoAccion();
        jp_Operaciones = new javax.swing.JPanel();
        masterScrollPane = new javax.swing.JScrollPane();
        tabla = new javax.swing.JTable();
        jp_DocumentoIdentificacion = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        try{
            mascara = new javax.swing.text.MaskFormatter("##/##/####");
        }catch(Exception e){
            System.out.println("Error en mascara");
        }

        ftxtFecIni = new javax.swing.JFormattedTextField();
        ftxtFecIni = new javax.swing.JFormattedTextField(mascara);

        try{
            mascara = new javax.swing.text.MaskFormatter("##/##/####");
        }catch(Exception e){
            System.out.println("Error en mascara");
        }

        ftxtFecFin = new javax.swing.JFormattedTextField();
        ftxtFecFin = new javax.swing.JFormattedTextField(mascara);

        btnBuscar = new javax.swing.JButton();
        try{
            mascara = new javax.swing.text.MaskFormatter("##/##/####");
        }catch(Exception e){
            System.out.println("Error en mascara");
        }

        numeroAccionesField = new javax.swing.JFormattedTextField();
        ftxtFecFin = new javax.swing.JFormattedTextField(mascara);

        jLabel5 = new javax.swing.JLabel();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(controlaccionescomercial.ControlAccionesComercialApp.class).getContext().getResourceMap(JP_AprobarAcciones.class);
        jp_Operaciones.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jp_Operaciones.border.title"))); // NOI18N
        jp_Operaciones.setName("jp_Operaciones"); // NOI18N

        javax.swing.GroupLayout jp_OperacionesLayout = new javax.swing.GroupLayout(jp_Operaciones);
        jp_Operaciones.setLayout(jp_OperacionesLayout);
        jp_OperacionesLayout.setHorizontalGroup(
            jp_OperacionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 581, Short.MAX_VALUE)
        );
        jp_OperacionesLayout.setVerticalGroup(
            jp_OperacionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 40, Short.MAX_VALUE)
        );

        masterScrollPane.setName("masterScrollPane"); // NOI18N

        tabla.setName("tabla"); // NOI18N
        tabla.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tabla.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablaMouseClicked(evt);
            }
        });
        tabla.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tablaKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tablaKeyReleased(evt);
            }
        });
        masterScrollPane.setViewportView(tabla);

        jp_DocumentoIdentificacion.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jp_DocumentoIdentificacion.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("jp_DocumentoIdentificacion.border.titleFont"))); // NOI18N
        jp_DocumentoIdentificacion.setName("jp_DocumentoIdentificacion"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        ftxtFecIni.setName("ftxtFecIni"); // NOI18N
        ftxtFecIni.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                ftxtFecIniKeyPressed(evt);
            }
        });

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(controlaccionescomercial.ControlAccionesComercialApp.class).getContext().getActionMap(JP_AprobarAcciones.class, this);
        ftxtFecFin.setAction(actionMap.get("buscar")); // NOI18N
        ftxtFecFin.setName("ftxtFecFin"); // NOI18N
        ftxtFecFin.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                ftxtFecFinKeyPressed(evt);
            }
        });

        btnBuscar.setAction(actionMap.get("buscar")); // NOI18N
        btnBuscar.setText(resourceMap.getString("btnBuscar.text")); // NOI18N
        btnBuscar.setName("btnBuscar"); // NOI18N

        numeroAccionesField.setAction(actionMap.get("buscar")); // NOI18N
        numeroAccionesField.setName("numeroAccionesField"); // NOI18N
        numeroAccionesField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                numeroAccionesFieldKeyPressed(evt);
            }
        });

        jLabel5.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        javax.swing.GroupLayout jp_DocumentoIdentificacionLayout = new javax.swing.GroupLayout(jp_DocumentoIdentificacion);
        jp_DocumentoIdentificacion.setLayout(jp_DocumentoIdentificacionLayout);
        jp_DocumentoIdentificacionLayout.setHorizontalGroup(
            jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jp_DocumentoIdentificacionLayout.createSequentialGroup()
                .addGroup(jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jp_DocumentoIdentificacionLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(numeroAccionesField, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jp_DocumentoIdentificacionLayout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ftxtFecIni, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 93, Short.MAX_VALUE)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(ftxtFecFin, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jp_DocumentoIdentificacionLayout.setVerticalGroup(
            jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_DocumentoIdentificacionLayout.createSequentialGroup()
                .addGroup(jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnBuscar)
                    .addComponent(jLabel4)
                    .addComponent(ftxtFecFin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(ftxtFecIni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(numeroAccionesField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jp_DocumentoIdentificacion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(masterScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 593, Short.MAX_VALUE)
                    .addComponent(jp_Operaciones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jp_DocumentoIdentificacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(masterScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 308, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jp_Operaciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void tablaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaMouseClicked
        // TODO add your handling code here:
        eventoSeleccionTable();
    }//GEN-LAST:event_tablaMouseClicked

    private void tablaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tablaKeyPressed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_tablaKeyPressed

    private void tablaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tablaKeyReleased
        // TODO add your handling code here:
        eventoSeleccionTable();
    }//GEN-LAST:event_tablaKeyReleased

    private void ftxtFecIniKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_ftxtFecIniKeyPressed
        if( evt.getKeyCode() == evt.VK_ENTER ){
            this.ftxtFecFin.requestFocus();
        }
    }//GEN-LAST:event_ftxtFecIniKeyPressed

    private void ftxtFecFinKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_ftxtFecFinKeyPressed
        if( evt.getKeyCode() == evt.VK_ENTER ){
            this.btnBuscar.requestFocus();
        }
    }//GEN-LAST:event_ftxtFecFinKeyPressed

    private void numeroAccionesFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_numeroAccionesFieldKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_numeroAccionesFieldKeyPressed

    private void eventoSeleccionTable(){
        try{
            int selected = this.tabla.getSelectedRow();
            if( selected > -1 ){
                TableBeanBinding_DatosAccionesAprobar t = this.listaDatos.get(tabla.convertRowIndexToModel(selected));
                //System.out.println( "Id Accion: " + t.getIdAccion() );
                //tbAccion = GestionDelegate.getInstance().buscarAccion( t.getIdAccion() );
   
                if( t != null){
                    JP_DetalleAccion panel = new JP_DetalleAccion( t );
                    if( ifrDetalleAccion == null || ifrDetalleAccion.isClosed() ){                        
                        ifrDetalleAccion = Utiles_Panel.creaVentanaInterna_Panel((ControlAccionesComercialView)this.getRef(), panel, "Detalle de Acciones - Control de Acciones");
                        panel.setDatos(t);
                        panel.setPadre(Utiles_Panel.TIPO_JINTERNALFRAME, ifrDetalleAccion);
                        panel.setRef( this );
                    }else{
                        JP_DetalleAccion panel_detalle = (JP_DetalleAccion)ifrDetalleAccion.getPanel();
                        panel_detalle.setDatos(t);
                    }
                }              

                jp_ope.getBtnGuardar().setEnabled( true );
                jp_ope.getBtnDeshacer().setEnabled( false );
                jp_ope.getBtnCerrar().setEnabled( true );
            }
        }catch( Exception ex ){
            System.out.println( "Error: eventoSeleccionTable " + ex.getMessage()  );
            //ex.printStackTrace();
        }
    }

    private void habilitarBotones( boolean ban ){
        jp_ope.getBtnGuardar().setEnabled( ban );
        jp_ope.getBtnDeshacer().setEnabled( ban);
        jp_ope.getBtnCerrar().setEnabled( !ban );
    }

    public boolean isSaveNeeded() {
        return saveNeeded;
    }

    private void setSaveNeeded(boolean saveNeeded) {
        if (saveNeeded != this.saveNeeded) {
            this.saveNeeded = saveNeeded;
            firePropertyChange("saveNeeded", !saveNeeded, saveNeeded);
        }
    }

    public boolean isRecordSelected() {
        return tabla.getSelectedRow() != -1;
    }

    @Action
    public Task buscar() {
        String inicio, fin;
        inicio = this.ftxtFecIni.getText();        
        fin = this.ftxtFecFin.getText();
        if( inicio.trim().equals("/  /") ||  inicio.trim().equals("") || fin.trim().equals("/  /") || fin.trim().equals("") ){
            helper.Utiles_MensajesDialogo.mensajeAlerta( "Ingrese un intervalo de fechas correcto" );
            inicio = "";
            fin = "";
        }
        cargaTabla(inicio, fin);
        return null;
    }
    @Override
    public Task modificar(){
        //return new Guarda(org.jdesktop.application.Application.getInstance(seguridad_cliente.Seguridad_ClienteApp.class));
        this.ind = 1;
        jp_ope.getBtnGuardar().setEnabled(true);
        jp_ope.getBtnDeshacer().setEnabled( true );
        jp_ope.getBtnCerrar().setEnabled( true );
        return null;
    }

    @Override
    public Task guardar() {
        return new Guarda(org.jdesktop.application.Application.getInstance(controlaccionescomercial.ControlAccionesComercialApp.class));
    }
    
    @Override
    public Task deshacer() {       
       this.inicializarBotones();
       eventoSeleccionTable();
       return null;
    }

    @Override
    public Task cerrar() {
        if( ifrDetalleAccion != null ){
            try {
                ifrDetalleAccion.setClosed(true);
                ifrDetalleAccion.dispose();
                ifrDetalleAccion = null;
            } catch (PropertyVetoException ex) {
                //Logger.getLogger(JP_AprobarAcciones.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        this.cerrarPadre();
        return null;
    }
    
    private class Guarda extends org.jdesktop.application.Task<Object, Void> {
        Guarda(org.jdesktop.application.Application app) {
            super(app);
        }
        @SuppressWarnings("unchecked")
        @Override protected Object doInBackground() {
            try {
                setProgress(0, 0, 4);
                setMessage("Verificando datos");
                setProgress(1, 0, 4);
                //entityManager.getTransaction().rollback();
                habilitarBotones( false );
                boolean ban = verificarDatos();
                boolean resultado = false;
                Thread.sleep(200L); // remove for real app
                setProgress(2, 0, 4);
                setMessage("Grabando en la Base de Datos");
                if(ban){
                     try{
                        procesarCambios();
                        resultado = true;
                    }catch( Exception ex ){
                        resultado = false;
                        jp_ope.getBtnGuardar().setEnabled( true );
                        ex.printStackTrace();
                        Utiles_MensajesDialogo.mensajeFracaso( "Error" + ex.getMessage() );
                    }
                }else{
                    resultado = false;
                    Utiles_MensajesDialogo.mensajeFracaso( "Datos inválidos" );
                    jp_ope.getBtnGuardar().setEnabled( true );
                }
                //entityManager.getTransaction().begin();
                Thread.sleep(250L); // remove for real app
                setProgress(3, 0, 4);

                setMessage("Refrescar Data");
                if( resultado ){
                    String inicio, fin;
                    inicio = "";
                    fin = "";
                    cargaTabla( inicio, fin);
                    Thread.sleep(100L); // remove for real app
                    setProgress(4, 0, 4);
                    Utiles_MensajesDialogo.mensajeExito();
                    inicializarBotones( );
                    eventoSeleccionTable();
                }
                Thread.sleep(50L); // remove for real app

            } catch(InterruptedException ignore) { }
            
            return null;  // return your result
        }
        @Override protected void succeeded(Object result) {
            
        }
        @Override protected void finished() {
            setSaveNeeded(false);
        }
    }
    
     private boolean verificarDatos( ){
        return true;
    }

    private void procesarCambios(  ) throws Exception{
        //int[] selected = this.tabla.getSelectedRows();
        //List< TableBeanBinding_DatosAccionesAprobar> toRemove = new ArrayList<TableBeanBinding_DatosClasificacionTipoAccionArea>(selected.length);
        for (int idx = 0; idx < tabla.getRowCount(); idx++) {
            TableBeanBinding_DatosAccionesAprobar t = this.listaDatos.get(tabla.convertRowIndexToModel(idx));

            tbAccion = GestionDelegate.getInstance().buscarAccion( t.getIdAccion() );
            tbAccion.setFlagAprobada( t.getAprobada() );

            GestionDelegate.getInstance().actualizarAccion(tbAccion);
        }
        setSaveNeeded(true);
    }

    private void refrescar(){
        try{
            //this.codTipoAccionField.setText( tbTipoAccion.getCodTipoAccion().toString() );
            
            System.out.println( "paso 1" );
            String inicio, fin;
            inicio = this.ftxtFecIni.getText().trim();
            fin = this.ftxtFecFin.getText().trim();
            cargaTabla( inicio, fin);
            System.out.println( "paso 2" );
            eventoSeleccionTable();
            System.out.println( "paso 3" );
            
        }catch( Exception ex ){
            System.out.println( "Error:refrescarDatos --> " + ex.getMessage() );
        }
        
    }

    private void inicializarBotones(){
        jp_ope.getBtnGuardar().setEnabled( false );
        jp_ope.getBtnDeshacer().setEnabled( false );
        jp_ope.getBtnCerrar().setEnabled( true );
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscar;
    private beansbinding.ComboBeanBindingArea comboBeanBindingArea1;
    private beansbinding.ComboBeanBindingTbClasificacionAccion comboBeanBindingTbClasificacionAccion1;
    private beansbinding.ComboBeanBindingTbTipoAccion comboBeanBindingTbTipoAccion1;
    private javax.swing.JFormattedTextField ftxtFecFin;
    private javax.swing.JFormattedTextField ftxtFecIni;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jp_DocumentoIdentificacion;
    private javax.swing.JPanel jp_Operaciones;
    private javax.swing.JScrollPane masterScrollPane;
    private javax.swing.JFormattedTextField numeroAccionesField;
    private javax.swing.JTable tabla;
    // End of variables declaration//GEN-END:variables
    private JP_Utiles_PanelBotonesMantenimiento jp_ope;
    private BindingGroup bindingGroup;
    //Datos los cuales van a realizar la persistencia del objeto

    private org.jdesktop.swingbinding.JTableBinding jTableBinding;
    private List<TableBeanBinding_DatosAccionesAprobar> listaDatos;
    //private java.util.List<TbUsuario> list;

    private int ind = 0;//0 nuevo 1 actualizar
    private boolean saveNeeded;

    TbAccion tbAccion = new TbAccion();
    javax.swing.text.MaskFormatter mascara;
    private helper.JInternalFrame_Modelo ifrDetalleAccion;
}
